import EventBus from './utils/eventBus';

App({
  globalData: {
    eventBus: EventBus,
    userInfo: null,
    settings: null,
    i18n: {
      currentLanguage: 'zh',
      translations: {
        zh: {
          // 中文翻译
        },
        en: {
          // 英文翻译
        }
      }
    }
  },

  onLaunch() {
    // 加载设置
    const settings = wx.getStorageSync('settings') || {
      soundEffects: true,
      backgroundMusic: true,
      languageIndex: 0,
      micPermission: false
    };
    this.globalData.settings = settings;

    // 监听语言变化
    this.globalData.eventBus.on('languageChange', this.handleLanguageChange.bind(this));
  },

  handleLanguageChange(event) {
    const lang = event.detail.language === 'English' ? 'en' : 'zh';
    this.globalData.i18n.currentLanguage = lang;
    // 通知所有页面更新语言
    this.globalData.eventBus.emit('updateLanguage', lang);
  }
}); 